<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" th:href="@{/}+'plugins/layui/css/layui.css'" media="all">
  <script th:src="@{/}+'plugins/layui/layui.js'"></script>
  <script th:src="@{/}+'js/jquery-2.2.4.min.js'"></script>
  <script th:src="@{/}+'js/tool.js'"></script>
  <style type="text/css">
	.layui-form .layui-form-item{
		width:90%;
	}
	</style>
<script th:inline="javascript">
/*<![CDATA[*/
var areaCode=/*[[${areaCode}]]*/     
var id=/*[[${id}]]*/     
/*]]>*/
</script>
</head>
<body style="margin-top: 10px">
<form class="layui-form"  lay-filter="myform">
<input type="hidden" name="id">
<input type="hidden" name="areaCode">
  <div class="layui-form-item">
    <label class="layui-form-label" th:text="#{eq.Township}">乡镇名称</label>
    <div class="layui-input-block">
      <input type="text" name="name" required lay-verify="required" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label" th:text="#{eq.NO}">编码</label>
    <div class="layui-input-block">
      <input type="text" name="code" placeholder="系统自动生成" readonly="readonly" autocomplete="off" class="layui-input">
    </div>
  </div>
  <button id="submitBtn" class="layui-btn" style="display:none" lay-submit lay-filter="submitme" th:text="#{eq.Save}">保存</button>
</form>
<script>
layui.use(['table','form'], function(){
  var table = layui.table,form = layui.form;
  if(areaCode&&areaCode!=null){
	  $("input[name=areaCode]").val(areaCode);
  }else{
	  
	  loadData();
  }
  function loadData(){
	 var entity = getEntityInfo(id,"town/getById");
      form.val("myform",entity);
 }
  form.on('submit(submitme)', function(data){
		var values = {};
		$(":input").each(function(i,v){
			values[v.name] = v.value;
		})
		$.ajax({
			url: 'town/save',
			data: values,
			type:'POST',
			dataType:'JSON',
			success: function(ret){
				parent.loadGrid(ret.id);
				layer.msg(i18n('eq.Saves'));
				var index = parent.layer.getFrameIndex(window.name); 
			    parent.layer.close(index); 
			}
		})
		return false; 
	  })
});
</script>
</body>
</html>